'use strict';

const crypto = require('crypto');
const redis = require('redis');
const dbutility = require('./dbutility');
const logger = require('./logutility').logger('utility');

/**
 * 加密
 * 
 * @param {string}pwd 需要进行加密的密码
 * @return {string}
 */
function encrypt(pwd) {
    //密码加盐
    let temp = 'e0' + pwd + pwd.length;
    //MD5加密
    return crypto.createHash('md5').update(temp).digest('hex').toUpperCase();
}

/**
 * 创建快递柜密码
 * 
 * @param {string}cabNo 快递柜编号
 * @return {string}
 */
function createCabPwd(cabNo) {
    let temp = cabNo + (new Date()).getTime();
    return encrypt(temp).substring(10, 14);
}

exports.encrypt = encrypt;
exports.createCabPwd = createCabPwd;